import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { fileURLToPath, URL } from 'node:url'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import ElementPlus from 'unplugin-element-plus/vite'

export default ({ mode }) => defineConfig({
    plugins: [
        vue(),
        Components({
            resolvers: [ElementPlusResolver({ importStyle: 'sass' })],
        }),
        ElementPlus()
    ],
    resolve: {
        alias: {
            '@': fileURLToPath(new URL('./src', import.meta.url)),
            '~assets': fileURLToPath(new URL('./src/assets', import.meta.url))
        }
    },
    server: {
        proxy: {
            '/api': {
                target: 'http://192.168.116.10:8090/api',
                changeOrigin: true,
                rewrite: (path) => path.replace(/^\/api/, '')
            },
            '/ws': {
                target: 'http://192.168.116.10:8090',
                changeOrigin: true,
                ws: true,
                rewrite: (path) => path.replace(/^\/ws/, ''),
                headers: { 'Connection': 'keep-alive', 'Upgrade': 'websocket' }
            }
        },
    },
    css: {
        preprocessorOptions: {
            scss: {
                additionalData: `@use "@/styles/element/index.scss" as *;`,
            },
        },
    },
    build: {
        assetsDir: 'static',
        rollupOptions: {
            output: {
                assetFileNames: 'static/[name]-[hash][extname]'
            }
        }
    }
})